// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_INV_CAPP
// * CreateDate    : 2013-12-20 23:31:41
// * Creater       : CodeSmith
// * LastChangeDate: 2013-12-20 23:31:41
// * LastChanger   : 2013-12-20 23:31:41
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Inv
{
/// <summary>
    /// InvCapp
    /// </summary>
    public partial class InvCappBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objInvCappEntity">Entity</param>
        /// <returns>Entity</returns>
        public static InvCappEntity GetInvCapp(InvCappEntity objInvCappEntity)
        {
            return DataAccess.SelectSingle<InvCappEntity>(objInvCappEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objInvCappEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertInvCapp(InvCappEntity objInvCappEntity)
        {
            return DataAccess.Insert(objInvCappEntity);
        }

        public static bool InsertInvCapp(List<InvCappEntity> objInvCappEntityList)
        {
            return DataAccess.Insert(objInvCappEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objInvCappEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateInvCapp(InvCappEntity objInvCappEntity)
        {
            return DataAccess.Update(objInvCappEntity);
        }

        public static bool UpdateInvCapp(List<InvCappEntity> objInvCappEntityList)
        {
            return DataAccess.Update<InvCappEntity>(objInvCappEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objInvCappEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteInvCapp(InvCappEntity objInvCappEntity)
        {
            return DataAccess.Delete(objInvCappEntity);
        }

        public static bool DeleteInvCapp(List<InvCappEntity> objInvCappEntityList)
        {
            return DataAccess.Delete<InvCappEntity>(objInvCappEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetInvCappAll()
        {
            return DataAccess.SelectAllDataSet<InvCappEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<InvCappEntity> GetInvCappAllList()
        {
            return DataAccess.SelectAll<InvCappEntity>();
        }
        #endregion

        public static DataSet GetAllDsByCondition(int pageIndex, int pageCount, string condition)
        {
            string sql = "";
            if (string.IsNullOrEmpty(condition))
            {
                string sqlSource = @"select top {0} *,(select count(1) from INV_CAPP) as cnt
from INV_CAPP
where id not in (
    select top ({1}*({2}-1)) id from INV_CAPP order by created_date
) order by created_date desc";
                sqlSource = string.Format(sqlSource, pageCount, pageCount, pageIndex);
                sql = @"select app.*,u1.firstName as CREATED_USER,u2.firstName as UPDATED_USER 
from ({0}) app
left join BPMDB.dbo.PW_User u1 on app.CREATED_BY=u1.userNo
left join BPMDB.dbo.PW_User u2 on app.UPDATED_BY=u2.userNo";
                sql = string.Format(sql, sqlSource);
            }
            else
            {
                sql = @"select top {0} *,(select count(1) from ({3}) t) as cnt
from ({3}) t
where t.id not in (
    select top ({1}*({2}-1)) id from ({3}) t order by created_date
) order by created_date desc";
                string sqlSource = @"select app.*,u1.firstName as CREATED_USER,u2.firstName as UPDATED_USER 
from INV_CAPP app
left join BPMDB.dbo.PW_User u1 on app.CREATED_BY=u1.userNo
left join BPMDB.dbo.PW_User u2 on app.UPDATED_BY=u2.userNo
where 1=1 ";
                sqlSource += condition;
                sql = string.Format(sql, pageCount, pageCount, pageIndex, sqlSource);
            }
            return DataAccess.SelectDataSet(sql);
        }

	}
	
	
}	

